const install = (Vue, vm) => {
  // 创建api对象(默认为空)
  vm.$u.api = {};
  // 首页数据API
  const getIndexData = (params) => vm.$u.get("/api/index", params); //首页数据
  // 认证相关API
  const authUserLogin = (params) => vm.$u.post("/api/auth/login", params); //用户登录
  const authUserRegister = (params) => vm.$u.post("/api/auth/register", params); //用户注册
  const authUserLogout = () => vm.$u.post("/api/auth/logout"); //退出登录
  const getOssToken = () => vm.$u.get("/api/auth/oss/token"); //获取阿里云OSS Token

  // 用户相关API
  const getUserInfo = () => vm.$u.get("/api/user"); //获取用户信息
  const updateUserInfo = (params) => vm.$u.put("/api/user", params); //更新用户信息
  const uploadUserAvatar = (params) => vm.$u.post("/api/user/avatar", params); //更新用户头像

  // 商品相关API
  const getGoodsDetail = (params) => vm.$u.get(`/api/goods/${params}`); //获取商品详情
  const handleGoodCollect = (params) =>
    vm.$u.post(`/api/collects/goods/${params}`); //操作商品收藏
  const getGoodsCategory = (params) => vm.$u.get("/api/goods", params); //获取商品分类
	
	// 商品
	vm.$u.api.getGoodsList = (params = {}) => vm.$u.get(`/api/goods`,params);//商品列表
	vm.$u.api.getGoodsDetail = id => vm.$u.get(`/api/goods/${id}`);//商品详情
	vm.$u.api.getCollect = (page=1) => vm.$u.get('/api/collects',{page}) //获取收藏商品
	vm.$u.api.isCollect = id => vm.$u.post(`/api/collects/goods/${id}`);//商品收藏或取消
  // 购物车相关API
  const handleAddCart = (params) => vm.$u.post("/api/carts", params); //添加商品到购物车
  const getCartList = () => vm.$u.get(`/api/carts`); //获取购物车列表(不含商品信息)
  const getCartGoods = () => vm.$u.get(`/api/carts?include=goods`); //获取购物车列表(含商品信息)
  const changeGoodSelect = (params) =>
    vm.$u.patch("/api/carts/checked", { cart_ids: params }); //切换商品选中状态
  const handleGoodNum = (cart, num) => vm.$u.put(`/api/carts/${cart}`, { num }); //修改购物车商品数量
  const handleDeleteGood = (cart) => vm.$u.delete(`/api/carts/${cart}`); //移除购物车商品
  // 订单相关API
  const handleCheckOrder = () => vm.$u.get("/api/orders/preview"); //订单预览列表
  const handleSubmitOrder = (params) => vm.$u.post("/api/orders", params); //提交订单
  const checkOrderList = () => vm.$u.get(`/api/orders`); //查看订单列表
  const checkOrderDetail = (order) => vm.$u.get(`/api/orders/${order}`); //查看订单详情(404)
  const getLogisticsStatus = (order) =>
    vm.$u.get(`/api/orders/${order}/express`); //物流详情
  const handleConfirmOrder = (order) =>
    vm.$u.get(`/api/orders/${order}/confirm`); //确认收货
  const handleEvaluateOrder = (order) =>
    vm.$u.get(`/api/orders/${order}/comment`); //评价订单

  // 支付相关API
  const getPayQRcode = (order) => vm.$u.get(`/api/orders/${order}/pay`); //获取支付二维码
  const getPayStatus = (order) => vm.$u.get(`/api/orders/${order}/status`); //获取支付状态

  // 收藏相关API
  const getCollections = () => vm.$u.get(`/api/collects`); //获取收藏列表
  const handleCollect = (id) => vm.$u.post(`/api/collects/goods/${id}`); //操作商品收藏

  // 地址管理相关API
  const getLocationData = () => vm.$u.get("/api/city"); // 获取省市县数据
  const addAddress = (params) => vm.$u.post("/api/address", params); // 添加地址
  const getAddressList = () => vm.$u.get("/api/address"); // 获取地址列表
  const checkAddressDetail = (address) => vm.$u.get(`/api/address/${address}`); // 地址详情(携带参数展示减少HTTP请求)
  const updateAddress = (id, params) => vm.$u.put(`/api/address/${id}`, params); // 更新地址信息(包含设置默认功能)
  const handleDelAddress = (id) => vm.$u.delete(`/api/address/${id}`); // 删除地址
 // /api/orders/{order}/paytest
 // 模式支付
   const getpaytestos = (order, params) => vm.$u.patch(`/api/orders/${order}/paytest`, params); // 更新地址信息(包含设置默认功能)
	  const getpayaliyun = (order, params) => vm.$u.get(`/api/orders/${order}/pay`,params)
  // 将自定义接口统一挂载到vm.$u.api对象
  vm.$u.api = {
    getIndexData,
		getpaytestos,
		getpayaliyun,
    authUserLogin,
    getUserInfo,
    authUserRegister,
    updateUserInfo,
    authUserLogout,
    getOssToken,
    uploadUserAvatar,
    getGoodsDetail,
    handleGoodCollect,
    handleAddCart,
    getCartList,
    getGoodsCategory,
    getCartGoods,
    changeGoodSelect,
    handleGoodNum,
    handleDeleteGood,
    handleCheckOrder,
    handleSubmitOrder,
    checkOrderDetail,
    checkOrderList,
    getCollections,
    handleCollect,
    getLocationData,
    addAddress,
    getAddressList,
    checkAddressDetail,
    updateAddress,
    handleDelAddress,
    getPayQRcode,
    getPayStatus,
    getLogisticsStatus,
    handleConfirmOrder,
    handleEvaluateOrder,
  };
};

export default install;
